package cn.edu.zafu.bigdata.hzq;

import java.io.*;
import java.net.*;

public class Client {
    public static void main(String[] args) {
        String host = "192.168.16.40"; // 服务端的IP地址
        int port = 3000; // 服务端监听的端口

        try (Socket socket = new Socket(host, port);
             PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
             BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
             BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in))) {

            System.out.println("Connected to the server.");

            // 读取用户输入并发送给服务端
            String userInput;
            while ((userInput = stdIn.readLine()) != null) {
                out.println(userInput);
                System.out.println("Server response: " + in.readLine());
            }
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host " + host);
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
